package org.example.springtrans.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.springtrans.service.LogService;
import org.example.springtrans.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/propaga")
public class PropagationController {

    @Autowired
    private UserService userService;

    @Autowired
    private LogService logService;

    @Transactional(propagation = Propagation.REQUIRED)
    @RequestMapping("/p1")
    public String p1(String name, String password) {
        // 用户注册
        userService.registryUser(name, password);
        logService.insertLog(name, "用户注册");
        return "p1";
    }
}
